/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Controller;

import GUI.EnigmaGUIMainWindow;
import GUI.EnigmaPreferences;
import Model.EnigmaModel;
import Model.GameStateListener;
import java.io.*;
/**
 *
 * @author snowangelic
 */
public class ReplayGameController  extends EnigmaController implements GameStateListener {

    ReplayReader replay;
    public ReplayGameController(EnigmaModel model,EnigmaGUIMainWindow gui, File replayFile) throws FileNotFoundException{
        this.model=model;
        this.gui=gui;
        gui.setController(this);
        model.addGameStateListener(this);
        replay=new ReplayReader(this,replayFile);
    }

    @Override
    public void mouseMoved(MouseMovedCommand command) {
        if(command.getSender() instanceof ReplayReader){
            mouseX+=command.getXPos();
            mouseY+=command.getYPos();
        }
    }

    @Override
    public void keyPressed(int keyCode) {
        if(keyCode==EnigmaPreferences.getInstance().getPauseKeyCode()){
            model.pauseGame();
        }
    }

    public void gameStateChanged(int newGameState) {
        replay.gameStateChanged(newGameState);

    }

    @Override
    public void scrollInventory(ScrollInventoryCommand command) {
        if(command.getSender() instanceof ReplayReader)
            model.scrollInventory();
    }

    @Override
    public void useActiveItem(UseActiveItemCommand command) {
        if(command.getSender() instanceof ReplayReader)
            model.useActiveItem();
    }

    @Override
    public void saveReplay(File file) {
        replay.moveReplayFile(file);
    }

}
